import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn } from "typeorm";
import { ManualTimestamp } from "../decorators/manual-timestamp.decorator";
import { CharacterEntity } from "./character.entity";

@Entity("character_stones")
@ManualTimestamp()
export class CharacterStoneEntity {
  @PrimaryGeneratedColumn()
  id!: number;

  @Column("int", { name: "characterId" })
  characterId!: number;

  @Column("varchar", { length: 64, comment: "魂蛋名称" })
  name!: string;

  @Column("int", { default: 1, comment: "魂蛋等级" })
  level!: number;

  @Column("varchar", { length: 128, nullable: true, comment: "魂蛋描述" })
  description!: string;

  @Column("varchar", { length: 32, nullable: true, comment: "魂蛋类型" })
  type!: string;

  @Column("int", { default: 0, comment: "魂蛋品质" })
  quality!: number;

  @Column("datetime", { name: "created_at", comment: "创建时间" })
  created_at!: Date;

  @Column("datetime", { name: "updated_at", nullable: true, comment: "更新时间" })
  updated_at!: Date | null;

  // 关联关系
  @ManyToOne(() => CharacterEntity, (character) => character.stones)
  @JoinColumn({ name: "characterId" })
  character!: CharacterEntity;
}
